//
//  NetWork.m
//  URLSessionTest
//
//  Created by mac on 2017/7/4.
//  Copyright © 2017年 yyb. All rights reserved.
//

#import "NetWork.h"
#import "NetWorkManager.h"
@implementation NetWork

+ (void)requestWithMethod:(NSString *)method
                   andURL:(NSString *)urlString
                andParams:(NSDictionary *)params
                   andCer:(NSString *)cerName
     andUseJSONSerializer:(BOOL )useJSONSerializer
        completionHandler:(void (^)(NSData *  data, NSURLResponse *  response, NSError *  error))completionHandler{
    NetWorkManager *manger = [[NetWorkManager alloc] initWithCompletionHandler:completionHandler];
    NetWorkSerializer *serializer = [[NetWorkSerializer alloc] initWithURL:urlString andMethod:method andUseJSONSerializer:useJSONSerializer andParams:params];
    manger.serializer = serializer;
    if (cerName) {
        NSData *cer = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:cerName ofType:@"cer"]] ;
        NetWorkSecurity *security = [[NetWorkSecurity alloc] init];
        [security addSSLPinning:cer andAllowInvalidCertificates:YES andValidatesDomainName:NO andSSLPinningMode:TWAFSSLPinningModeCertificate];
        manger.security = security;
    }
    [manger fire];
}

@end
